<template>
  <el-menu
    active-text-color="#409eff"
    background-color="#304156"
    class="el-menu-vertical-demo"
    :default-active="defUrl"
    text-color="#fff"
    :collapse="isCollapse"
    :collapse-transition="true"
    router
    unique-opened
  >
    <el-menu-item index="/">
      <i class="iconfont homepage"></i>
      <span>首页</span>
    </el-menu-item>
    <el-sub-menu :index="p.name" v-for="p in menus" ::key="p.id">
      <template #title>
        <i class="iconfont" :class="p.icon"></i>
        <span>{{ p.title }}</span>
      </template>
      <template v-for="sub in p.children" ::key="sub.id">
        <el-menu-item :index="'/' + p.name + '/' + sub.name + ''" v-if="sub.hidden===0">
          <i class="iconfont" :class="sub.icon"></i>
          {{ sub.title }}</el-menu-item
        >
      </template>
    </el-sub-menu>
  </el-menu>
</template>

<script setup lang="ts">
import { useUserStore } from "@/store/user";
import { type } from "os";
import { ref, watch } from "vue";
import { useRoute } from "vue-router";
const userStore = useUserStore();
const menus = userStore.routes;

const defUrl = ref("/index");
const route = useRoute();

watch(
  () => route.path,
  () => {
    // 不需要参数直接path
    defUrl.value = route.path;
  }
);

const { isCollapse } = defineProps(["isCollapse"]);
console.log(isCollapse);
</script>

<style scoped lang="less"></style>
